<?php Soul_Template_Resource::getInstance()->addReferenceScript('region','/pub/skin/share/js/region.js'); ?>
<?php if($this->getMultiple()): ?>
<select id="<?php echo $this->getId() ?>_province" class="region"></select>
<select id="<?php echo $this->getId() ?>_city" class="region"></select>
<select id="<?php echo $this->getId() ?>_district" class="region"></select>
<button type="button" onclick="javascript:<?php echo $this->getId() ?>AddRegion()"><?php echo Soul_Globalization_Factory::getTranslator()->__('share.button.add')?></button>
<div>
<ul id="<?php echo $this->getId() ?>_container" class="road-selected-list">
</ul>
</div>
<input type="text" id="<?php echo $this->getId() ?>" value="" <?php echo $this->getValidateRuleHtml()?> style="display:none"/>
<script language="javascript" type="text/javascript">
var <?php echo $this->getId()?>_region = new ecbond.RegionSelect('<?php echo $this->getId()?>');
function <?php echo $this->getId() ?>AddRegion(code){
    var roadCode = code? code: <?php echo $this->getId()?>_region.getValue();
    if(roadCode == ''){
        return;
    }
    
    var codes = $('input[name="<?php echo $this->getName()?>"]');
    for(var i = 0; i < codes.length; i++){
        if($(codes[i]).val() == roadCode){
            return;
        }
    }

    var id = '#<?php echo $this->getId() ?>_container';
    var html = '<li><span>' + ecbond.getRegionName(roadCode)+ '</span>';
    html += '<a class="button" href="javascript:void(0)" onclick="javascript:$(this).parent().remove()"><?php echo Soul_Globalization_Factory::getTranslator()->__('share.button.delete')?> </a>';
    html += '<input type="hidden" name="<?php echo $this->getName()?>" value="' + roadCode + '"></li>';
    $(id).append(html);
}

<?php
if(is_array($this->getValue())):
    foreach($this->getValue() as $value):
?>
<?php echo $this->getId() ?>AddRegion('<?php echo $value['id'] ?>');
<?php 
    endforeach;
endif;
?>
</script>
<?php else: 
if($this->getReadonly()):
?>
<span id="<?php echo $this->getId() ?>_readonly">{region_<?php echo $this->getValue() ?>}</span>
<script language="javascript" type="text/javascript">
replaceRegionCode('<?php echo $this->getId() ?>_readonly', null, true);
</script>
<?php else: ?>
<select id="<?php echo $this->getId() ?>_province" class="region"></select>
<select id="<?php echo $this->getId() ?>_city" class="region"></select>
<select id="<?php echo $this->getId() ?>_district" class="region"></select>
<input type="text" id="<?php echo $this->getId() ?>" name="<?php echo $this->getName()?>" value="<?php echo $this->getValue()?>" <?php echo $this->getValidateRuleHtml()?> style="display:none"/>
<script language="javascript" type="text/javascript">
var <?php echo $this->getId()?>_region = new ecbond.RegionSelect('<?php echo $this->getId()?>');
</script>
<?php endif;endif; ?>